<?php

namespace app\http\middleware;

class signature
{
    public function handle($request, \Closure $next)
    {
        if(config('app.is_sign')){
            $sign=$request->param('sign','');
            $arr=decrypt($sign);
            if(!$arr) return json(['msg'=>'Signature error or invalid','code'=>ERRNO['SIGNERR']]);
            //拼接到post参数里
            unset($arr['appName']);
            unset($arr['timestamp']);
            if(count($arr)){
               foreach ($arr as $key=>$value){
                   $_POST[$key]=$value;
               }
            }
        }

        return $next($request);
    }
}
